package com.ruoyi.project.jiaqin.answerreply.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.jiaqin.answerreply.domain.JiaqinAnswerReply;
import com.ruoyi.project.jiaqin.answerreply.service.IJiaqinAnswerReplyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问答评论回复Controller
 *
 * @author LCL
 * @date 2021-11-19
 */
@Controller
@RequestMapping("/jiaqin/answerreply")
public class JiaqinAnswerReplyController extends BaseController
{
    private String prefix = "jiaqin/answerreply";

    @Autowired
    private IJiaqinAnswerReplyService jiaqinAnswerReplyService;

    @RequiresPermissions("jiaqin:answerreply:view")
    @GetMapping()
    public String answerreply()
    {
        return prefix + "/answerreply";
    }

    /**
     * 查询问答评论回复列表
     */
    @RequiresPermissions("jiaqin:answerreply:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiaqinAnswerReply jiaqinAnswerReply)
    {
        startPage();
        List<JiaqinAnswerReply> list = jiaqinAnswerReplyService.selectJiaqinAnswerReplyList(jiaqinAnswerReply);
        return getDataTable(list);
    }

    /**
     * 导出问答评论回复列表
     */
    @RequiresPermissions("jiaqin:answerreply:export")
    @Log(title = "问答评论回复", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiaqinAnswerReply jiaqinAnswerReply)
    {
        List<JiaqinAnswerReply> list = jiaqinAnswerReplyService.selectJiaqinAnswerReplyList(jiaqinAnswerReply);
        ExcelUtil<JiaqinAnswerReply> util = new ExcelUtil<JiaqinAnswerReply>(JiaqinAnswerReply.class);
        return util.exportExcel(list, "answerreply");
    }

    /**
     * 新增问答评论回复
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存问答评论回复
     */
    @RequiresPermissions("jiaqin:answerreply:add")
    @Log(title = "问答评论回复", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiaqinAnswerReply jiaqinAnswerReply)
    {
        return toAjax(jiaqinAnswerReplyService.insertJiaqinAnswerReply(jiaqinAnswerReply));
    }

    /**
     * 修改问答评论回复
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JiaqinAnswerReply jiaqinAnswerReply = jiaqinAnswerReplyService.selectJiaqinAnswerReplyById(id);
        mmap.put("jiaqinAnswerReply", jiaqinAnswerReply);
        return prefix + "/edit";
    }

    /**
     * 修改保存问答评论回复
     */
    @RequiresPermissions("jiaqin:answerreply:edit")
    @Log(title = "问答评论回复", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiaqinAnswerReply jiaqinAnswerReply)
    {
        return toAjax(jiaqinAnswerReplyService.updateJiaqinAnswerReply(jiaqinAnswerReply));
    }

    /**
     * 删除问答评论回复
     */
    @RequiresPermissions("jiaqin:answerreply:remove")
    @Log(title = "问答评论回复", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiaqinAnswerReplyService.deleteJiaqinAnswerReplyByIds(ids));
    }
}
